<<<<<<< HEAD
<?php 
header("Content-Type: text/html;charset=utf-8");
include_once 'includes/res.php';
include_once 'includes/header.php';

require_once 'service/UserService.php';

if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'register') {
    $email = $_REQUEST['email'];
    $display_name = $_REQUEST['display_name'];
    $password = $_REQUEST['password'];
    $userService = new UserService();
    $flag = $userService->register($email, $display_name, $password);
    header("location:register-success.php");
}

?>
<div class="container">
    <div class="row">
        <div class="span8">
          <form id="regform" class="form-horizontal" method="post">
            <input type="hidden" name="action" value="register"/>
            <fieldset>
              <legend>用户注册</legend>
              <div class="control-group">
                <label class="control-label" for="focusedInput">邮箱</label>
                <div class="controls">
                  <input id="email" class="input-xlarge focused" name="email" type="text" value="">
                </div>
              </div>
              <div class="control-group">
                <label class="control-label" for="focusedInput">昵称</label>
                <div class="controls">
                  <input id="display_name" class="input-xlarge focused" name="display_name" type="text" value="">
                </div>
              </div>
              <div class="control-group">
                <label class="control-label" for="focusedInput">密码</label>
                <div class="controls">
                  <input id="password" class="input-xlarge focused" name="password" type="text" value="">
                </div>
              </div>
              <div class="form-actions">
                <button type="submit" class="btn btn-primary">保存</button>
                <button type="reset" class="btn">取消</button>
              </div>
            </fieldset>
          </form>
        </div>
    </div>
</div>
<?php 
include_once './includes/footer.php';
?>

<script type="text/javascript">

$(function() {
	
	$('.help-inline').each(function(){
		$(this).prev().addClass('error').parent().parent().addClass('error');
	});
	
	var error = function(el, msg){
		el.addClass('error');
		if (!el.next().is('.help-inline'))
			$('<span class="help-inline" />').text(msg).insertAfter(el);
		else
			el.next().text(msg);
		el.parent().parent().addClass('error');
		return false;
	}

	$("#email").blur(function() {
		var email = $('#email').val();
		$.get("ajax-service.php?checkemail="+email, function(data) {
		    if (data == '1') {
			    $('body').data('isemailused',1);
			    //alert($('body').data('isemailused'));
			    return error($('#email'), '该Email已经注册过了');
		    }
		})
	});

	$("#email").focus(function() {
		if( $("#email").next().is('.help-inline') ) {
			$("#email").next().remove();
		}
		$("#email").removeClass('error').parent().parent().removeClass('error');
		$('body').data('isemailused',0);
	});
	
	$("#regform").submit(function() {
		$('#regform .error').removeClass('error');
		$('#regform .help-inline').remove();
		var email = $('#email').val();
		var display_name = $('#display_name').val();
		var password = $('#password').val();
		if(!email) {
			return error($('#email'), '请输入您的Email');
		} 
		else if(!display_name) {
			return error($('#display_name'), '请输入昵称');
		} 
		else if (!password){
			return error($('#password'), '请输入密码');	
		}
		else if (password && password.length < 6) {
			return error($('#password'), '密码长度必须大于6位');
		}
		
		if (!/^\s*[\w\-\+_]+(\.[\w\-\+_]+)*\@[\w\-\+_]+\.[\w\-\+_]+(\.[\w\-\+_]+)*\s*$/.test(email))
			return error($('#email'), '请检查您输入的Email的格式');
		
		/*$.get("ajax-service.php?checkemail="+email, function(data) {
		    if (data == '1') {
			    return error($('#email'), '该Email已经注册过了');
		    }
		})*/
		if($('body').data('isemailused') != 0) {
			return error($('#email'), '该Email已经注册过了');
		}
		
		return false;
	});
});
=======
<?php 
header("Content-Type: text/html;charset=utf-8");
include_once 'includes/res.php';
include_once 'includes/header.php';

require_once 'service/UserService.php';

if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'register') {
    $email = $_REQUEST['email'];
    $display_name = $_REQUEST['display_name'];
    $password = $_REQUEST['password'];
    $userService = new UserService();
    $flag = $userService->register($email, $display_name, $password);
    header("location:register-success.php");
}

?>
<div class="container">
    <div class="row">
        <div class="span8">
          <form id="regform" class="form-horizontal" method="post">
            <input type="hidden" name="action" value="register"/>
            <fieldset>
              <legend>用户注册</legend>
              <div class="control-group">
                <label class="control-label" for="focusedInput">邮箱</label>
                <div class="controls">
                  <input id="email" class="input-xlarge focused" name="email" type="text" value="">
                </div>
              </div>
              <div class="control-group">
                <label class="control-label" for="focusedInput">昵称</label>
                <div class="controls">
                  <input id="display_name" class="input-xlarge focused" name="display_name" type="text" value="">
                </div>
              </div>
              <div class="control-group">
                <label class="control-label" for="focusedInput">密码</label>
                <div class="controls">
                  <input id="password" class="input-xlarge focused" name="password" type="text" value="">
                </div>
              </div>
              <div class="form-actions">
                <button type="submit" class="btn btn-primary">保存</button>
                <button type="reset" class="btn">取消</button>
              </div>
            </fieldset>
          </form>
        </div>
    </div>
</div>
<?php 
include_once './includes/footer.php';
?>

<script type="text/javascript">

$(function() {
	
	$('.help-inline').each(function(){
		$(this).prev().addClass('error').parent().parent().addClass('error');
	});
	
	var error = function(el, msg){
		el.addClass('error');
		if (!el.next().is('.help-inline'))
			$('<span class="help-inline" />').text(msg).insertAfter(el);
		else
			el.next().text(msg);
		el.parent().parent().addClass('error');
		return false;
	}

	$("#email").blur(function() {
		var email = $('#email').val();
		$.get("ajax-service.php?checkemail="+email, function(data) {
		    if (data == '1') {
			    $('body').data('isemailused',1);
			    //alert($('body').data('isemailused'));
			    return error($('#email'), '该Email已经注册过了');
		    }
		})
	});

	$("#email").focus(function() {
		if( $("#email").next().is('.help-inline') ) {
			$("#email").next().remove();
		}
		$("#email").removeClass('error').parent().parent().removeClass('error');
		$('body').data('isemailused',0);
	});
	
	$("#regform").submit(function() {
		$('#regform .error').removeClass('error');
		$('#regform .help-inline').remove();
		var email = $('#email').val();
		var display_name = $('#display_name').val();
		var password = $('#password').val();
		if(!email) {
			return error($('#email'), '请输入您的Email');
		} 
		else if(!display_name) {
			return error($('#display_name'), '请输入昵称');
		} 
		else if (!password){
			return error($('#password'), '请输入密码');	
		}
		else if (password && password.length < 6) {
			return error($('#password'), '密码长度必须大于6位');
		}
		
		if (!/^\s*[\w\-\+_]+(\.[\w\-\+_]+)*\@[\w\-\+_]+\.[\w\-\+_]+(\.[\w\-\+_]+)*\s*$/.test(email))
			return error($('#email'), '请检查您输入的Email的格式');
		
		/*$.get("ajax-service.php?checkemail="+email, function(data) {
		    if (data == '1') {
			    return error($('#email'), '该Email已经注册过了');
		    }
		})*/
		if($('body').data('isemailused') != 0) {
			return error($('#email'), '该Email已经注册过了');
		}
		
		return false;
	});
});
>>>>>>> 20d6c557d209a3f376420616f57b4bd953611975
</script>